package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketAdmin;
import com.cskaoyan.market.db.domain.MarketAdminExample;
import com.cskaoyan.market.db.mapper.MarketAdminMapper;
import com.cskaoyan.market.util.MybatisUtils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2024/6/17 11:26
 * @Version 1.0
 */
public class AdminAuthServiceImpl implements AdminAuthService{
    @Override
    public MarketAdmin login(String username, String password) {
        //service里面应该进一步调用mapper
        SqlSession sqlSession = MybatisUtils.getSession();
        MarketAdminMapper marketAdminMapper = sqlSession.getMapper(MarketAdminMapper.class);
        //执行查询 操作
        //example的主要使用目的是为了去构造出where条件
        MarketAdminExample marketAdminExample = new MarketAdminExample();

        MarketAdminExample.Criteria criteria = marketAdminExample.createCriteria();
        //作用就是最终拼接处了and username = #{username}
        criteria.andUsernameEqualTo(username);
        //最终拼接出了 and password = #{password}
        criteria.andPasswordEqualTo(password);


        MarketAdmin admin = marketAdminMapper.selectOneByExample(marketAdminExample);

        sqlSession.close();
        return admin;
    }
}
